//
//  ViewController.m
//  MY_IGList_demo
//
//  Created by mac on 2019/3/18.
//  Copyright © 2019 Yilian. All rights reserved.
//

#import "ViewController.h"
#import "PersonModel.h"
#import "SchoolModel.h"
#import "GoodsModel.h"
#import "SchoolSectionController.h"
#import "PersonSectionController.h"
#import "HScrollSectionController.h"
@interface ViewController ()<IGListAdapterDataSource>
@property (nonatomic,strong) IGListAdapter *adapter;
@property (nonatomic,strong) UICollectionView *collectionView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    
    [self setUpCollectionView];
    //初始化IGListAdapter
    self.adapter = [[IGListAdapter alloc]initWithUpdater:[IGListAdapterUpdater new] viewController:self workingRangeSize:1];
    //关联collectionView
    self.adapter.collectionView = self.collectionView;
    //设置dataSource,实现3个代理方法
    self.adapter.dataSource = self;
}

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
//    self.collectionView.frame = self.view.bounds;
}

- (NSArray *)datas{
    NSArray *arr_name = @[@"li",@"wang",@"zhang"];
    NSArray *arr_age = @[@"1",@"2",@"3"];
    NSArray *arr_desc = @[@"1111",@"2222222",@"333333333333333333"];
    
    NSArray *arr_school_name = @[@"清华",@"北大",@"河大"];
    NSArray *arr_level = @[@"1",@"2",@"3"];
    NSArray *arr_school_desc = @[@"111111",@"2222222",@"333333333333333333"];
    
    NSMutableArray *arr = [NSMutableArray array];
    for (int i = 0; i < arr_name.count; i++) {
        PersonModel *model = [PersonModel  new];
        model.name = [NSString stringWithFormat:@"%@-%@",model.arrOfM[i],arr_name[i]];
        model.age = arr_age[i];
        model.desc = arr_desc[i];
        [arr addObject:model];
        
        SchoolModel *school_model = [SchoolModel  new];
        school_model.name = arr_school_name[i];
        school_model.level = arr_level[i];
        school_model.desc = arr_school_desc[i];
        [arr addObject:school_model];
        
    }
    
    SchoolModel *school_model = [SchoolModel  new];
    school_model.name = @"hhhh";
    [arr addObject:school_model];
    [arr addObject:@10];
    
    
    NSArray *array = [NSArray arrayWithArray:arr];
    return array;
}

- (NSArray *)school_datas{
    NSArray *arr_name = @[@"清华",@"北大",@"河大",@"1",@"2",@"3"];
    NSArray *arr_level = @[@"1",@"2",@"3",@"1",@"2",@"3"];
    NSArray *arr_desc = @[@"111111",@"2222222",@"333333333333333333",@"111111",@"111111",@"111111"];
    NSMutableArray *arr = [NSMutableArray array];
    for (int i = 0; i < arr_name.count; i++) {
        SchoolModel *model = [SchoolModel  new];
        model.name = arr_name[i];
        model.level = arr_level[i];
        model.desc = arr_desc[i];
        [arr addObject:model];
    }
    NSArray *array = [NSArray arrayWithArray:arr];
    
    return array;
}

- (void)setUpCollectionView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.minimumLineSpacing = 0;//设置每一行之间的间距
    layout.minimumInteritemSpacing = 0;
    self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
    self.collectionView.backgroundColor = UIColor.clearColor;
    [self.view addSubview:self.collectionView];
}

- (NSArray<id <IGListDiffable>> *)objectsForListAdapter:(IGListAdapter *)listAdapter{
    NSMutableArray *arr = [NSMutableArray array];
//    for (SchoolModel *model in [self school_datas]) {
//        [arr addObject:model];
//    }
//    for (PersonModel *model in [self datas]) {
//        [arr addObject:model];
//    }

    NSLog(@"%@",arr);
    return  [self datas];
}

- (IGListSectionController *)listAdapter:(IGListAdapter *)listAdapter sectionControllerForObject:(id)object{
    if ([object isKindOfClass:[PersonModel class]]) {
        return [PersonSectionController new];
    }else if ([object isKindOfClass:[SchoolModel class]]){
        return [SchoolSectionController new];
    }else if ([object isKindOfClass:[NSNumber class]]){
        return [HScrollSectionController new];
    }else{
        return nil;
    }
}

- (nullable UIView *)emptyViewForListAdapter:(IGListAdapter *)listAdapter{
    return nil;
}


@end
